#include "../Base/Log.h"
#include "../Render/RenderEngine.h"

#include "ImageObject.h"

namespace cy_univerX
{
namespace world2d
{

	CImageNode::CImageNode(const std::string&path, CSpaceNode* parent):m_Color(1,1,1,1),m_Uv(0,0,1,1)
	{
		m_TexPtr = render::CTextureMgr::Instance().GetTexture(path, 0, render::EU_GpuRead);
		if (!m_TexPtr)
			assert(false);
		if (m_TexPtr->GetType() != render::CTextureBase::TT_2D)
		{
			log::CLogger::Instance().Output(log::LL_Error, "CImageNode require 2d texture");
			assert(false);
		}

		m_Tex = (render::CTexture2D*)m_TexPtr.get();
		m_LocalSize.Set((float)m_Tex->GetDesc().Width, (float)m_Tex->GetDesc().Height);
	}

	CImageNode::~CImageNode()
	{
	}

	void CImageNode::Render(const float& window_w, const float& window_h, render::CSimpleEffectBase* eff)const
	{
		math::CVector3f uv[4];
		uv[0].Set(m_Uv.m_Array[0],	m_Uv.m_Array[1],	1);
		uv[1].Set(m_Uv.m_Array[2],	m_Uv.m_Array[1],	1);
		uv[2].Set(m_Uv.m_Array[0],	m_Uv.m_Array[3],	1);
		uv[3].Set(m_Uv.m_Array[2],	m_Uv.m_Array[3],	1);
		DoRenderQuad(window_w, window_h, eff, m_Color, 
			m_Tex, m_LocalSize, uv);

		ChildRender(window_w, window_h, eff);
	}

}
}